<template>
  <el-dialog
    title="设置"
    :visible.sync="$attrs.visableIf"
    @close="handleCloseDialog"
    width="560px"
    append-to-body
    class="borderb_dia"
  >
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      size="small"
      label-position="left"
    >
      <div class="tips line_h_22">
        <div class="f-16 mb-8 fw-5">间隔提示</div>
        <div class="c_text">当主讲人前后两条消息发言间隔不足10秒时，前一条消息转发出去，等待10秒，再转发下一条消息。</div>
      </div>
      <el-form-item label="转发消息最小时间间隔：" prop="checked" class="delay">
        <el-input
          v-model="form.min"
          placeholder=""
          style="width: 90px"
          class="mr-6"
          @blur="onBlur('min')"
        ></el-input>
        秒（10-180）
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button size="small" @click="handleCloseDialog">取消</el-button>
      <el-button size="small" type="primary" @click="submitForm"
        >确认</el-button
      >
    </div>
  </el-dialog>
</template>

<script>
// import { validPhone, validPassword } from "@/utils/validate";
// import { editInfo } from "@/api/advmaster";
export default {
  data() {
    return {
      form: {
        name: "",
        min: 5,
        max: 10,
      },
      // 表单校验
      rules: {
        name: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        email: [
          {
            required: true,
            type: "email",
            message: "请输入正确的邮箱地址",
            trigger: "blur",
          },
        ],
        password: [],
        status: [{ required: true, message: "请选择状态", trigger: "change" }],
      },
    };
  },
  props: {
    rowitem: {
      default: null,
    },
  },
  created() {},
  methods: {
    handleCloseDialog() {
      this.$emit("update:visableIf", false);
    },

    onBlur(type) {
      // 使用正则表达式匹配正整数
      const regex = /^[1-9]\d*$/;
      // 如果输入的值不是正整数，则将其设置为上一个有效值
      if (!regex.test(this.form[type])) {
        if (type == "min") {
          this.form.min = 5;
        } else {
          this.form.max = 10;
        }
      } else {
        if (this.form[type] > 999) {
          this.form[type] = 999;
        }
      }
    },

    handleDefault() {
      this.form.min = 5;
      this.form.max = 10;
    },

    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != undefined) {
            // editInfo(this.form).then(() => {
            //   this.$modal.msgSuccess('修改成功')
            //   this.handleCloseDialog();
            //   this.$emit('getList');
            // })
          }
        }
      });
    },
  },
};
</script>

<style scoped lang="scss">
.tips {
  width: 100%;
  background-color: #fed;
  border: 1px solid #ffdbb6;
  border-radius: 2px;
  padding: 16px;
  margin-bottom: 20px;
}
.divi {
  display: inline-block;
  margin: 0 6px;
}
</style>
